package com.th.therp.context;

/**
 * ThreadLocal，存储当前线程的用户ID和角色信息
 */
public class BaseContext {

    private static ThreadLocal<Long> currentId = new ThreadLocal<>();
    private static ThreadLocal<Integer> currentRole = new ThreadLocal<>();

    public static Long getCurrentId() {
        return currentId.get();
    }

    public static void setCurrentId(Long userId) {
        currentId.set(userId);
    }

    public static Integer getCurrentRole() {
        return currentRole.get();
    }

    public static void setCurrentRole(Integer role) {
        currentRole.set(role);
    }

    public static void remove() {
        currentId.remove();
        currentRole.remove();
    }
}
